package day05test;

import java.util.Arrays;
import java.util.Random;

public class Test01 {
    public static void main(String[] args) {
        //MultiTable
        //生成九九乘法表
        for (int i=1;i<=9;i++){
            for (int j=1;j<=i;j++){
                System.out.print(i+"*"+j+"="+i*j+"\t");
            }
            System.out.println();
        }
        //数组练习，声明、初始化、访问、便利、复制
        int[] arr=new int[10];
        //arr={1,2,3,4,5,6,7,8,9,10};
        double[] arr1=new double[]{1.2,1.3};
        String[] arr2=new String[]{"hello","world"};
        //string[] arr3=new string[]{"hello","world"};
        int[] arr4={1,2,3};
        int[] arr5;
        arr5=new int[]{1,2,3};
        System.out.println(arr5.length);
        arr[0]=100;
        System.out.println(arr[0]);
        //遍历
        Random random=new Random();
        int[] arr6=new int[10];
        //数据初始化
        for (int i=0;i<arr6.length;i++){
            arr6[i]=random.nextInt(100);
            System.out.println(arr6[i]);
        }
        int[] b= new int[10];
        System.arraycopy(arr6,0,b,0,10);
        System.out.println("b数组"+b.length);
        int[] c= Arrays.copyOf(arr6,10);
        System.out.println("c数组"+c.length);
        arr6=Arrays.copyOf(arr6,arr6.length+1);//扩容

        //求数组中的最大值、最小值
        int[] num=new int[10];
        for (int i=0;i<num.length;i++){
            num[i]=random.nextInt(100);
            System.out.print(num[i]+"\t");
        }
        int max=num[0];
        for (int i=1;i<num.length;i++){
            if (num[i]>max){
                max=num[i];
            }
        }
        System.out.println("最大值"+max);
        int min=num[0];
        for (int i=1;i<num.length;i++){
            if (num[i]<min){
                min=num[i];
            }
        }
        System.out.println("最小值"+min);

        //排序
        Arrays.sort(num);
        System.out.println("排序：");
        for (int i=0;i<num.length;i++){
            System.out.print(num[i]+"\t");
        }
        //倒序
        System.out.println("倒序：");
        for (int i=num.length-1;i>=0;i--){
            System.out.print(num[i]+"\t");
        }
        System.out.println("第一个有元素："+num[0]);
    }
}
